/**
 * @description 地点相关的API处理
 */

import { post } from "@/util/request"
import { useStore } from "vuex";
const store = useStore();

// 获取地点列表
const getAddressList = async ({
    url = "/address-api/getAddressList",
    params = Object,
    success = Function,
    error = Function,
    complete = Function,
}) => {
    try {
        const res = await post(url, {
            ...params
        })
        if (res.status === "0000") {
            success(res.data);
            const { list } = data;
            store.dispatch("setAddressList", list)
        } else {
            error(res)
        }

    } catch (error) {
        error(error)
    } finally {
        complete()
    }
}


// 删除地点
const deleteAddress = async ({
    url = "/address-api/deleteAddress",
    params = Object,
    success = Function,
    error = Function,
    complete = Function,
}) => {
    try {
        const res = await post(url, {
            ...params
        })
        if (res.status === "0000") {
            success(res);
        } else {
            error(res)
        }

    } catch (error) {
        error(error)
    } finally {
        complete()
    }
}


export {
    getAddressList, deleteAddress
}